<template>
	<view class="content">
		<tabBar :currentIndex="2"></tabBar>
		<view v-if="authentication === '2' || starFlag === '1'" class="head">
			<view class="line1">
				<view class="user_img">
					<image :src="img_url + detailList.avatar"></image>
					<image v-if="detailList.starFlag === '1'" class="img_daka" src="/static/img/community/ic_daka.png"
						style="position:absolute;right:14rpx;bottom:-8rpx;width: 94rpx;height:40rpx;"></image>
				</view>

				<view class="user_info">
					<view ><text class="title-name person-item">{{detailList.nickName}}</text>
						<image v-if="detailList.sex === '2'" src="/static/img/sex_woum.png"></image>
						<image v-else src="/static/img/ic_mail.png"></image>
					</view>

					<view class="person-item"><text>医院：{{detailList.hospitalId_dictText}}</text></view>
					<view class="person-item"><text>科室：{{detailList.depId_dictText}}</text></view>
					<view class="person-item"><text>职务：{{detailList.post_dictText}}</text></view>
					<view class="person-item"><text>职称：{{detailList.professionalTitle_dictText}}</text></view>
				</view>
			</view>

			<view class="line2"></view>
			<view class="line3" @click="clkAuthentication(2)">
				<image src="/static/img/community/ic_edit.png"></image><text style="font-size:20rpx"> 修改个人信息</text>
			</view>
		</view>
		<view v-else class="head-unau" style="background-color: #ffff;">
			<view class="line1">

				<view class="user_info">
					<image :src="img_url + detailList.avatar" class="user_img"></image>
					<text class="title-name">{{detailList.nickName}}</text>
					<image v-if="detailList.sex === '2'" src="/static/img/sex_woum.png"></image>
					<image v-else src="/static/img/ic_mail.png"></image>
				</view>
			</view>
			<view class="cer-wrapper">
			 <img class="cer-img" src="../../../static/img/community/certi.png" alt="" srcset="">
			 <view class="text">您还未认证资料</view>
			 </view>
			<u-button v-if="authentication=='0'" @click="clkAuthentication(1)" :hair-line="true" :ripple="true" class="btn-auth">我要认证</u-button>
			<u-button v-if="authentication=='1'"  :hair-line="true" :ripple="true" class="btn-auth">审核中</u-button>
		</view>

		<view class="center">
			<view class="flex-start" @click="joinPath('/pages/myWallet/walletIndex')">
				<image class="wallet-image" src="/static/img/community/ic_wallet.png"></image>
				<text>钱包</text>
			</view>
			<view class="u-badge-wrap" @click="openPage(pathMessage)">
				<image class="message-image" src="/static/img/ic_message.png"></image>
				<u-badge v-if="UnReadNum" type="warning " :is-center="true"  :is-dot="true"></u-badge>
			</view>
			<text class="message-text" @click="openPage(pathMessage)">消息</text>

		</view>


		<view class="list-wrap">
			<u-cell-group title-bg-color="rgb(243, 244, 246)">
				<u-cell-item :titleStyle="{fontWeight: 500}" title="个人介绍" @click="openPage(pathIntroduce, detailList.intro)"/>
				<u-cell-item v-if="authentication === '2' || starFlag === '1'" :titleStyle="{fontWeight: 500}"  :value="`共${totalArticle}个帖子`" title="我的贴子" @click="openPage(pathInvitation)"/>
				<u-cell-item :titleStyle="{fontWeight: 500}" title="修改绑定手机号" @click="openPage(pathBindPhone)" :value="`${phoneNumberStr}`"/>
				<u-cell-item :titleStyle="{fontWeight: 500}" title="收藏夹" @click="openPage(pathFavorites)"/>
				<u-cell-item :titleStyle="{fontWeight: 500}" title="关注" @click="openPage(pathFollow)"/>
			</u-cell-group>
		</view>
	</view>
</template>

<script>
		import tabBar from '@/components/tabBar.vue'
	import {
		mapState,
		mapActions,
		mapMutations
	} from 'vuex'
	import apis from '@/apis.js'
	export default {
		components: {
			tabBar
		},
		data() {
			return {
				pathIntroduce: "pages/user/introduce/introduce",
				pathMessage: "pages/user/message/message",
				pathFollow: "pages/user/follow/follow",
				pathBindPhone: "pages/user/bindPhone/bindPhone",
				pathFavorites: "pages/user/favorites/index/index",
				pathInvitation: 'pages/user/invitation/invitation',
				title: 'Hello',
				yiyuan: "厦门大学翔安附属医院",
				username: "厦门大学",
				new_message: true,
				authentication: false,
				detailList: {
					phone: 0
				},
				UnReadNum: 0,
				starFlag: '1',
				listQuery: {
					pageNo: 1,
					pageSize: 10,
					subjectType:''
				},
				totalArticle: 0
			}
		},
		computed: {
			...mapState(['img_url']),
			/**
			 *  @function 当前手机号加密
			 */
			phoneNumberStr() {
				if (this.detailList.phone) {
					return this.detailList.phone.replace(/^(\d{3})\d{4}(\d+)/, "$1****$2")
				} else {
					return 0
				}
				
			}
		},
		onLoad() {
			this.getMessageUnReadNum()
		},
		onShow() {
			this.getDetail()
			this.getList()
		},
		methods: {
			getList() {
				this.$http.get(apis.getMyArticleList, this.listQuery).then(res => {
					if (res.data.code === 200) {
						this.totalArticle = res.data.result.total
					}
				})
			},
			getDetail() {
				this.$http.get(apis.userDetail).then(res => {
					if (res.data.code === 200) {
						this.authentication = res.data.result.authenticationFlag
						this.starFlag = res.data.result.starFlag
						this.detailList = res.data.result
						this.$store.commit("setUserInfo", res.data.result);
						uni.setStorageSync('userInfo', res.data.result)
					}
				})
			},
			getMessageUnReadNum() {
				this.$http.get(apis.getCountUnReadNewsRecordByType, {}).then(res => {
					if (res.data.code === 200) {
						this.UnReadNum = res.data.result
					}
				})
			},
			clkAuthentication(type) {
				if (this.authentication === '1') {
					uni.showToast({
						title: '审核中',
						icon: 'none'
					})
					return
				}
				if (this.authentication === '2') {
					uni.navigateTo({
						url: "/pages/authentication/editor?auditType=" + type 
					})
				} else {
					uni.navigateTo({
						url: "/pages/authentication/remind?auditType=" + type 
					})
				}
				
			},
			openPage(path, intro) {
				console.log(intro, 'intro')
				let url = ''
				if (intro) {
					url = path + '?value=' + intro
				} else {
					url = path + '?value='
				}
				
				this.$u.route({ 
					url: url
				})
			},
			clkAlterUserInfo: function() {
				this.openPage("pages/user/userinfo/userinfo")
			},
			joinPath(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "uview-ui/index.scss";
	.content {
		text-align: center;
		height: 100vh;
		background-color: white;
		padding: 18rpx;

		.head {
			height: auto;
			background: #A4CDE8;
			opacity: 1;
			border-radius: 4rpx;

			.line1 {
				display: flex;
				flex: row nowrap;
				padding: 37rpx 2rpx 16rpx 31rpx;

				.user_img {
					position: relative;
					margin-right: 16rpx;
					width: 115rpx;
					height: 115rpx;

					image:first-child {
						margin-right: 16rpx;
						width: 115rpx;
						height: 115rpx;
						background: #4D5B80;
						border-radius: 50%;
						opacity: 1;
					}
				}

				.user_info {
					display: flex;
					flex-flow: column nowrap;
					align-items: flex-start;

					text {
						font-size: $artical-text-font;
						font-family: SimHei;
						font-weight: 400;
						color: #4D5B80;
						opacity: 1;
					}
					.title-name {
							font-size: $title-font;
						

					}

					image {
						width: 24rpx;
						height: 24rpx;
					}
				}


			}

			.line2 {
				border: 1rpx solid #EFF1F7;
				opacity: 1;
			}

			.line3 {
				display: flex;
				flex-flow: row nowrap;
				justify-content: flex-end;
				padding: 11rpx;
				padding-bottom: 20rpx;

				text {
					font-size: 14rpx;
					font-family: SimHei;
					font-weight: 400;
					color: #4D5B80;
					opacity: 1;
					border-bottom: 1rpx solid #4D5B80;
					padding-bottom: 2rpx;
				}

				image {
					width: 40rpx;
					height: 40rpx;
					margin-right: 19rpx;
				}
			}
		}

		.head-unau {
			height: auto;
			background: #A4CDE8;
			opacity: 1;
			border-radius: 3rpx;
			padding-bottom: 31rpx;
			.line1 {
				display: flex;
				flex: row nowrap;
				padding: 37rpx 2rpx 16rpx 31rpx;



				.user_info {
					display: flex;
					justify-content: center;
					align-items: center;

					text {
						font-size: 31rpx;
						font-family: SimHei;
						font-weight: 400;
						line-height: 40rpx;
						color: #4D5B80;
						opacity: 1;
					}

					image {
						width: 24rpx;
						height: 24rpx;
					}


					.user_img {
						margin-right: 29rpx;
						width: 115rpx;
						height: 115rpx;
						background: #4D5B80;
						border-radius: 50%;
						opacity: 1;
					}
					
					.user-sex {
						margin-left: 10rpx;
						width: 39rpx;
						height: 39rpx;
					}
				}


			}

			.btn-auth {
				width: 290rpx;
				height: 96rpx;
				background: #3FA7FF;
				box-shadow: -4rpx -4rpx 12rpx #FFFFFF;
				opacity: 1;
				border-radius: 8rpx;
				
				font-size: 31rpx;
				font-family: SimHei;
				font-weight: 400;
				line-height: 40rpx;
				color: #FFFFFF;
				width: 202rpx;
				height: 58rpx;
				background: #3FA7FF;
				box-shadow: -3px -3px 7px 0px rgba(255, 255, 255, 0.9), 2px 3px 9px 0px #B0AFB8;
				border-radius: 6px;
			}
		}

		.center {
			display: flex;
			justify-content: flex-end;
			align-items: center;
			padding: 25rpx;
			margin-top: 20rpx;
			margin-bottom: 30rpx;

			
			image {
				height: 42rpx;
				width: 42rpx;
				margin-right: 10rpx;
			}
			.wallet-image {
				width: 71rpx;
				height: 67rpx;
			}
			.message-image {
				width: 53rpx;
				height: 68rpx;
			}
			.message-text {
				margin-left: 10rpx;

			}
		}


	}


	.u-cell-icon {
		width: 36rpx;
		height: 36rpx;
		margin-right: 8rpx;
	}

	.u-badge-wrap {
		width: 40rpx;
		position: relative;
		margin-right: 15rpx;
		margin-left: 38rpx;
	}
	.cer-wrapper {
		display: flex;
		align-items: center;
		justify-content: center;
		margin-bottom: 38rpx;
		flex-direction: column;
		.text {
			font-size: 24rpx;
			font-family: Source Han Sans CN;
			font-weight: 500;
			color: #535353;
			margin-top: 19rpx;
		}
	}
	.cer-img {
		width: 196rpx;
		height: 139rpx;
	}
	.person-item {
		margin-bottom: 8rpx;
	}
</style>
